package cn.net.xinyi.xs.dao.dialect;

import cn.net.xinyi.xs.util.StringUtil;

public class MySQLDialect implements Dialect {

	public String getLimitString(String sql, boolean hasOffset) {
		return new StringBuffer(sql.length() + 20).append(
				StringUtil.trimSQL(sql, SQL_END_DELIMITER)).append(
				hasOffset ? " limit ?,?" : " limit ?")
				.append(SQL_END_DELIMITER).toString();
	}

	public String getLimitString(String sql, int offset, int limit) {
		sql = StringUtil.trimSQL(sql, SQL_END_DELIMITER);
		StringBuffer sb = new StringBuffer(sql.length() + 20);
		sb.append(sql);
		if (offset > 0) {
			sb.append(" limit ").append(offset).append(",").append(limit)
					.append(SQL_END_DELIMITER);
		} else {
			sb.append(" limit ").append(limit).append(SQL_END_DELIMITER);
		}
		return sb.toString();
	}

	public String getCountSqlString(String sql) {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean supportsLimit() {
		return true;
	}
}
